import React from 'react'
import BaseFilter, {filterCodes} from "../Base/BaseFilter";
import ComboBox from "../ComboBox";
import BaseFormItem from "../Base/BaseFormItem";
import {isBoolean} from "lodash-es";

const compData = [
    {code: '1', name: '是'},
    {code: '0', name: '否'},
];

class SwitchFilterBase extends BaseFilter {

    comboData = [
        filterCodes.eq, filterCodes.noEq
    ];

    dealCompValue(value) {
        return value ? '1' === value : value;
    }

    compRender(moreProps = {}) {
        const {value} = moreProps;
        return (<ComboBox
            {...moreProps}
            needOptionLocale={true}
            allowClear={true}
            needPH={false}
            compData={compData}
            value={isBoolean(value) ? value ? '1' : '0' : ''}
        />)
    }
}

export default class SwitchFilter extends BaseFormItem {
    Comp = SwitchFilterBase
}